package com.tool.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextField;
import javax.swing.border.MatteBorder;

import com.tool.ResourceBundleHelper;

public class AbstractImportUtilUI extends CoreUI {

	private static final long serialVersionUID = 5977763346548128018L;

	JLabel billTypeLabel;
	JComboBox billTypeComboBox = null;
	JLabel dataCenterLabel;
	JComboBox dataCenterComboBox = null;

	JLabel srcFileLabel;
	JTextField srcFileTxt;
	JButton srcFileBtn;
	JLabel logFileLabel;
	JTextField logFileTxt;
	JButton logFileBtn;

	JButton btnImport;

	public AbstractImportUtilUI() {
		super();
		setPreferredSize(new Dimension(480, 340));
		initUI();
	}

	private void initUI() {
		resHelper = new ResourceBundleHelper(AbstractImportUtilUI.class.getName());

		setMenuBar(createMenus());
		setTitle(resHelper.getString("Frame.title"));
		final MatteBorder bottomLineBorder = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.GRAY);

		setLayout(null);

		// Bill Type
		billTypeLabel = new JLabel(resHelper.getString("billTypeLabel"));
		billTypeLabel.setBounds(new Rectangle(20, 20, 100, 20));
		billTypeLabel.setBorder(bottomLineBorder);
		add(billTypeLabel, null);

		billTypeComboBox = new JComboBox();
		billTypeComboBox.setBounds(new Rectangle(125, 20, 200, 20));
		add(billTypeComboBox, null);

		// Data Center
		dataCenterLabel = new JLabel(resHelper.getString("dataCenterLabel"));
		dataCenterLabel.setBounds(new Rectangle(20, 45, 100, 20));
		dataCenterLabel.setBorder(bottomLineBorder);
		add(dataCenterLabel, null);

		dataCenterComboBox = new JComboBox();
		dataCenterComboBox.setBounds(new Rectangle(125, 45, 200, 20));
		add(dataCenterComboBox, null);

		// Src File Select
		srcFileLabel = new JLabel(resHelper.getString("srcFileLabel"));
		srcFileLabel.setBounds(new Rectangle(20, 70, 100, 20));
		srcFileLabel.setBorder(bottomLineBorder);
		add(srcFileLabel, null);

		srcFileTxt = new JTextField();
		srcFileTxt.setBounds(new Rectangle(125, 70, 200, 20));
		srcFileTxt.setEnabled(false);
		add(srcFileTxt, null);

		srcFileBtn = new JButton("...");
		srcFileBtn.setBounds(new Rectangle(330, 70, 40, 20));
		srcFileBtn.addActionListener(new SrcFileSelectAction());
		add(srcFileBtn, null);

		// log File Select
		logFileLabel = new JLabel(resHelper.getString("logFileLabel"));
		logFileLabel.setBounds(new Rectangle(20, 95, 100, 20));
		logFileLabel.setBorder(bottomLineBorder);
		add(logFileLabel, null);

		logFileTxt = new JTextField();
		logFileTxt.setBounds(new Rectangle(125, 95, 200, 20));
		logFileTxt.setEnabled(false);
		add(logFileTxt, null);

		logFileBtn = new JButton("...");
		logFileBtn.setBounds(new Rectangle(330, 95, 40, 20));
		logFileBtn.addActionListener(new LogFileSelectAction());
		add(logFileBtn, null);

		// btnImport
		btnImport = new JButton(resHelper.getString("btnImport"));
		btnImport.setBounds(new Rectangle(20, 125, 100, 20));
		btnImport.addActionListener(new ImportAction());
		add(btnImport, null);

	}

	public JMenuBar createMenus() {
		JMenuBar menuBar = new JMenuBar();

		// ***** create File menu
		JMenu fileMenu = (JMenu) menuBar.add(new JMenu(resHelper.getString("FileMenu.file_label")));
		fileMenu.setMnemonic(resHelper.getMnemonic("FileMenu.file_mnemonic"));
		fileMenu.getAccessibleContext().setAccessibleDescription(resHelper.getString("FileMenu.accessible_description"));

		// createMenuItem(fileMenu, "FileMenu.about_label",
		// "FileMenu.about_mnemonic", "FileMenu.about_accessible_description",
		// new AboutAction());
		//
		// fileMenu.addSeparator();
		createMenuItem(fileMenu, "FileMenu.exit_label", "FileMenu.exit_mnemonic", "FileMenu.exit_accessible_description", new ExitAction());

		// ********create option Menu
		JMenu optionsMenu = (JMenu) menuBar.add(new JMenu(resHelper.getString("OptionsMenu.option_label")));
		optionsMenu.setMnemonic(resHelper.getMnemonic("OptionsMenu.option_mnemonic"));
		optionsMenu.getAccessibleContext().setAccessibleDescription(resHelper.getString("OptionsMenu.accessible_description"));

		// �����������
		createMenuItem(optionsMenu, "OptionsMenu.DCSet_label", "OptionsMenu.DCSet_mnemonic", "OptionsMenu.DCSet_accessible_description", new DCSetAction());
		// License����
		createMenuItem(optionsMenu, "OptionsMenu.license_label", "OptionsMenu.license_mnemonic", "OptionsMenu.license_accessible_description",
				new LicenseSetAction());

		return menuBar;
	}

	public static void main(String[] args) {

		AbstractImportUtilUI ui = new AbstractImportUtilUI();
		ui.showUI();
	}

	public JMenuItem createMenuItem(JMenu menu, String label, String mnemonic, String accessibleDescription, Action action) {
		JMenuItem mi = (JMenuItem) menu.add(new JMenuItem(resHelper.getString(label)));

		// mi.setBorder(BorderFactory.createEmptyBorder());
		mi.setMnemonic(resHelper.getMnemonic(mnemonic));
		mi.getAccessibleContext().setAccessibleDescription(resHelper.getString(accessibleDescription));
		mi.addActionListener(action);
		if (action == null) {
			mi.setEnabled(false);
		}
		return mi;
	}

	protected void about_ActionPerformed(ActionEvent e) {
	}

	protected void dataCenter_ActionPerformed(ActionEvent e) {
	}

	protected void licenseSet_ActionPerformed(ActionEvent e) {
	}

	protected void import_ActionPerformed(ActionEvent e) {
	}

	protected void srcFileSelect_ActionPerformed(ActionEvent e) {
	}

	protected void logFileSelect_ActionPerformed(ActionEvent e) {
	}

	protected void onLoad() {

	}

	class AboutAction extends AbstractAction {

		protected AboutAction() {
			super("AboutAction");
		}

		public void actionPerformed(ActionEvent e) {
			about_ActionPerformed(e);
		}
	}

	/**
	 * �����������
	 * 
	 * @author Evan.Hu
	 * 
	 */
	class DCSetAction extends AbstractAction {

		protected DCSetAction() {
			super("DCSetAction");
		}

		public void actionPerformed(ActionEvent e) {
			dataCenter_ActionPerformed(e);
		}
	}

	class LicenseSetAction extends AbstractAction {

		protected LicenseSetAction() {
			super("DCSetAction");
		}

		public void actionPerformed(ActionEvent e) {
			licenseSet_ActionPerformed(e);
		}
	}

	class ExitAction extends AbstractAction {

		protected ExitAction() {
			super("ExitAction");
		}

		public void actionPerformed(ActionEvent e) {
			System.exit(0);
		}
	}

	class ImportAction extends AbstractAction {

		protected ImportAction() {
			super("ImportAction");
		}

		public void actionPerformed(ActionEvent e) {
			import_ActionPerformed(e);
		}
	}

	class SrcFileSelectAction extends AbstractAction {

		protected SrcFileSelectAction() {
			super("SrcFileSelectAction");
		}

		public void actionPerformed(ActionEvent e) {
			srcFileSelect_ActionPerformed(e);
		}
	}

	class LogFileSelectAction extends AbstractAction {

		protected LogFileSelectAction() {
			super("LogFileSelectAction");
		}

		public void actionPerformed(ActionEvent e) {
			logFileSelect_ActionPerformed(e);
		}
	}
}
